package cn.itcast.itcaststore.service.Impl;

import cn.itcast.itcaststore.dao.Impl.IOderDao;
import cn.itcast.itcaststore.dao.OrderDao;
import cn.itcast.itcaststore.domain.Orderitem;
import cn.itcast.itcaststore.domain.Orders;
import cn.itcast.itcaststore.domain.Products;
import cn.itcast.itcaststore.service.OrderService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class IOrderService implements OrderService {
    private OrderDao orderDao=new IOderDao();

    @Override
    public void createOrders(Orders orders) {
        orderDao.create(orders);
    }

    @Override
    public ArrayList getTypeOrders(String type, Long by) {

        Orders orders=orderDao.getOrders(type,by);


        List<Orderitem> orderitemList=orderDao.getOrderitem(orders.getId());


        HashMap<Orderitem, Products> map = new HashMap<>();

        for (Orderitem orderitem : orderitemList) {

            Products products=orderDao.getProducts(orderitem.getProduct_id());

            map.put(orderitem,products);

        }

        ArrayList list = new ArrayList();
        list.add(orders);
        list.add(map);
        return list;
    }

    @Override
    public void updatePayOrder(String order_id) {
        orderDao.upatePay(order_id);
    }

    @Override
    public List getOrderList(String username) {
        List list=orderDao.getList(username);
        return list;
    }

    @Override
    public void delOrderByid(String id) {
        orderDao.delById(id);
    }


}
